﻿#include "stdafx.h"
#include "DefInfo/GameInfo.h"
#include "PressKeyUtil.h"
#include "DkActionUnholy.h"
#include "DefInfo/Team_Raid_Info.h"

DkActionUnholy::DkActionUnholy()
{
}


DkActionUnholy::~DkActionUnholy()
{
}

void DkActionUnholy::ChooseBattleAction()
{
	// 判断是否该有动作
	if (PressKeyUtil::inst().press_battle_enbale && GameInfo::inst().PlayerInBattle() && GameInfo::inst().TargetIsEnemy() && GameInfo::inst().GetTargetHp() != 0)
	{
		do
		{
			int loss_percent = (int)(GameInfo::inst().GetPlayer().LostHpPecent()*100.0f);
			// 灵界打击
			if (GameInfo::inst().IsActionNotCDAndInRange(Death_Strike))
			{
				int back_percent = (int)((GameInfo::inst().GetLostHP_InFiveSecond()*0.4f*100.0f) / GameInfo::inst().GetPlayer().player_hp_max);
				back_percent = 80;
				// todo; 这里要修正为平均掉血率
				if (GameInfo::inst().GetPlayerMana() >= 35)
				{
					if (loss_percent >= 50)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Death_Strike);
						break;
					}
				}
				// 是否有黑暗援助
				if (GameInfo::inst().GetPlayerBuffRemainTime(Dark_Succor) > 60)
				{
					if (loss_percent >= 40)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Death_Strike);
						break;
					}
					else if (loss_percent > 20 && back_percent >= 20)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Death_Strike);
						break;
					}
				}
				else if (GameInfo::inst().GetPlayerBuffRemainTime(Dark_Succor) > 0) {
					if (loss_percent >= 10)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Death_Strike);
						break;
					}
				}
			}
			// 打断施法,心灵冰冻
			if (GameInfo::inst().IsActionNotCDAndInRange(Mind_Freeze))
			{
				if (GameInfo::inst().GetTargetSpellCanInterupt())
				{
					PressKeyUtil::inst().SendKeyBySpellID(Mind_Freeze);
					break;
				}
			}
			// 5. 亡者复生
			if (GameInfo::inst().GetActionCDBySpellId(Raise_Dead) == 0)
			{
				if (!GameInfo::inst().HasOpenPetUI())
				{
					PressKeyUtil::inst().SendKeyBySpellID(Raise_Dead);
					break;
				}
			}
			// 9.是否 爆发 没有CD
			if (GameInfo::inst().IsActionNotCDAndInRange(Outbreak) && GameInfo::inst().GetRuneReadyCount() >= 1)
			{
				// 是否目标身上的恶性瘟疫cd<=2秒
				if (GameInfo::inst().GetTargetDebuffCD(Virulent_Plague) <= 15)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Outbreak);
					break;
				}
			}
			// D. 亡者大军 Army_of_the_Dead
			if (GameInfo::inst().GetActionCDBySpellId(Army_of_the_Dead) == 0 && GameInfo::inst().GetRuneReadyCount() >= 3)
			{
				PressKeyUtil::inst().SendKeyBySpellID(Army_of_the_Dead);
				break;
			}
			// E. 释放天启 275699, 
			if (GameInfo::inst().IsActionNotCDAndInRange(Apocalypse))
			{
				// 是否目标身上的溃烂之伤 大于等于4层
				if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) >= 4)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Apocalypse);
					break;
				}
			}
			// F. 黑暗突变
			if (GameInfo::inst().GetActionCDBySpellId(Dark_Transformation) == 0)
			{
				if (GameInfo::inst().HasOpenPetUI() && GameInfo::inst().GetPetHp() > 0)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Dark_Transformation);
					break;
				}
			}
			// G. 凋零缠绕
			if (GameInfo::inst().IsActionNotCDAndInRange(Death_Coil))
			{
				// 是否有末日突降
				if (GameInfo::inst().GetPlayerBuffRemainTime(Sudden_Doom) > 0)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
					break;
				}
			}
			// H. 及时使用凋零缠绕，防止能量溢出。
			if (GameInfo::inst().IsActionNotCDAndInRange(Death_Coil) && GameInfo::inst().GetPlayerMana() >= 86)
			{
				if (GameInfo::inst().GetActionCDBySpellId(Apocalypse) > 50)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
					break;
				}
				// 是否身上的脓疮传染 大于等于4层
				if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) > 4)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
					break;
				}
			}
			// I. 是否 枯萎凋零 没有CD
			if (GameInfo::inst().GetActionCDBySpellId(Death_and_Decay) == 0 && GameInfo::inst().GetRuneReadyCount() >= 1)
			{
				//if (GameInfo::inst().GetActionCDBySpellId(Apocalypse) > 0)
				{
					PressKeyUtil::inst().SendKey(VK_NUMPAD1);
					break;
				}
			}
			if (GameInfo::inst().GetActionCDBySpellId(Army_of_the_Dead) > 50)
			{
				// J. 如果目标身上有1个以上溃烂之伤，施放天灾打击 (或者暗影之爪，如果你点了这个天赋的话)。
				if (GameInfo::inst().IsActionNotCDAndInRange(Clawing_Shadows) && GameInfo::inst().GetRuneReadyCount() >= 1)
				{

					// 是否目标身上的溃烂之伤 大于等于1层				
					if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) > 1)
					{
						if (GameInfo::inst().GetActionCDBySpellId(Apocalypse) >= 50)
						{
							PressKeyUtil::inst().SendKeyBySpellID(Clawing_Shadows);
							break;
						}
					}
					if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) > 4)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Clawing_Shadows);
						break;
					}
				}

				// L.脓疮打击
				if (GameInfo::inst().IsActionNotCDAndInRange(Festering_Strike) && GameInfo::inst().GetRuneReadyCount() >= 2)
				{
					if (GameInfo::inst().GetActionCDBySpellId(Apocalypse) <= 30)
					{
						// 是否目标身上的溃烂之伤 小于6层
						if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) < 4)
						{
							PressKeyUtil::inst().SendKeyBySpellID(Festering_Strike);
							break;
						}
					}
					// 是否目标身上的溃烂之伤 小于6层
					if (GameInfo::inst().GetTargetDebuffStack(Festering_Wound) <= 3)
					{
						PressKeyUtil::inst().SendKeyBySpellID(Festering_Strike);
						break;
					}
				}
			}

			// K. Death_Coil 能量超过80点防止溢出
			if (GameInfo::inst().IsActionNotCDAndInRange(Death_Coil) && GameInfo::inst().GetPlayerMana() >= 80)
			{
				PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
				break;
			}

			// M. Death_Coil 
			if (GameInfo::inst().IsActionNotCDAndInRange(Death_Coil))
			{
				if (loss_percent < 30)
				{
					if (GameInfo::inst().GetPlayerMana() >= 40)
					{

						PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
						break;
					}
				}
				else if (GameInfo::inst().GetActionCDBySpellId(Death_Strike) > GameInfo::inst().GetGlobalCDExecute() && GameInfo::inst().GetPlayerMana() >= 75)
				{
					PressKeyUtil::inst().SendKeyBySpellID(Death_Coil);
					break;
				}
			}

		} while (false);
	}
	else if (PressKeyUtil::inst().press_battle_enbale && !GameInfo::inst().PlayerInBattle() && GameInfo::inst().TargetIsEnemy() && GameInfo::inst().GetTargetHp() != 0)
	{
		if (GameInfo::inst().IsActionNotCDAndInRange(Death_Grip))
		{
			PressKeyUtil::inst().SendKeyBySpellID(Death_Grip);
		}
	}
}
